#include "stdafx.h"
#include "TestSitePersist.h"
#include "SitePersist.h"
#include "DatabaseBase.h"
#include "UEConnectionManager.h"
#include "Site.h"

using namespace PDMS::PDMSDBIF;
using namespace PDMS::PDMSDomain;
CPPUNIT_TEST_SUITE_REGISTRATION( TestSitePersist );


TestSitePersist::TestSitePersist()
{
}


TestSitePersist::~TestSitePersist()
{
}

void TestSitePersist::testCreate()
{
	DatabaseBase DB( GET_REGISTER( DatabaseElementFactory, Design_VersionOne ) );
	DB.DataSource( _T( "D:\\DesignDBTemplate.mdb" ) );
	UEConnectionPtr ptr = DB.DataSource();

	SitePersist SP;
	SP.SetDatabase( &DB );

	Site *pSite = new Site;
	pSite->SetArea( 3 );
	pSite->SetNumber( 6 );
	pSite->SetFunction( _T("9") );

	UESoft::ErrorStatus es = SP.Create( pSite );
	ASSERT( es == UESoft::eOk );
	
	delete pSite;
	CPPUNIT_ASSERT( ptr != NULL );
	UEConnectionManager::Instance().CloseAllConnection();
}

void TestSitePersist::testUpdate()
{
	DatabaseBase DB( GET_REGISTER( DatabaseElementFactory, Design_VersionOne ) );
	DB.DataSource( _T( "D:\\DesignDBTemplate.mdb" ) );
	UEConnectionPtr ptr = DB.DataSource();

	SitePersist SP;
	SP.SetDatabase( &DB );

	Site *pSite = new Site;
	pSite->SetArea( 3 );
	pSite->SetNumber( 6 );
	pSite->SetFunction( _T("9") );

	UESoft::ErrorStatus es = SP.Update( pSite );
	ASSERT( es == UESoft::eOk );
	
	delete pSite;
	CPPUNIT_ASSERT( ptr != NULL );
	UEConnectionManager::Instance().CloseAllConnection();
}

void TestSitePersist::testRetrieve()
{

}
